#pragma once
#include <MAPISPI.h>
#include "WINPSTS_i.h"

extern LPALLOCATEBUFFER g_lpAllocateBuffer ;
extern LPALLOCATEMORE g_lpAllocateMore ;
extern LPFREEBUFFER g_lpFreeBuffer ;

#define WC_H(fnx)	\
	if (SUCCEEDED(hRes))	\
{	\
	hRes = (fnx);	\
}

#define	pidProfileMin					0x6600
#define PR_PROFILE_OFFLINE_STORE_PATH	PROP_TAG( PT_STRING8, pidProfileMin+0x10)
#define PR_OST_OLFI PROP_TAG(PT_BINARY, 0x7C07)

enum
{
	CLIENT_PST_PATH = 0,
	CLIENT_MDB_PROVIDER,
	NUM_CLIENT_PROPERTIES
};

const static SizedSPropTagArray(NUM_CLIENT_PROPERTIES, sptClientProps) =
{
	NUM_CLIENT_PROPERTIES,
	{
		PR_PROFILE_OFFLINE_STORE_PATH,
			PR_MDB_PROVIDER
	}
};



struct LTID
{
	GUID	guid;
	BYTE	globcnt[6];
	WORD	wLevel;
};


// OffLineFileInfo
typedef struct {
	ULONG    ulVersion;     // Structure version
	MAPIUID  muidReserved;
	ULONG    ulReserved;
	DWORD    dwAlloc;       // Number of primary source keys
	DWORD    dwNextAlloc;
	LTID     ltidAlloc;
	LTID     ltidNextAlloc;
} OLFI, *POLFI;


STDMETHODIMP GetGlobalProfileObject(LPMAPISUP lpMAPISupObj, LPPROFSECT * lppGlobalProfileObj);

HRESULT SetOLFIInOST(LPMDB lpMDB);

ULONG STDAPICALLTYPE MyFreeBuffer(LPVOID lpBuffer);


HRESULT SetOfflineStoreProps(LPPROFSECT lpProfSect,ULONG ulUIParam,BSTR path,BSTR name);


HRESULT WINAPI InitStoreProps (LPMAPISUP pSupObj,
							   LPPROFSECT pProfObj,
							   LPPROVIDERADMIN pAdminProvObj);


STDMETHODIMP CreateStoreEntryID( LPSTR lpstrPath, BYTE **ppStoreEID, ULONG *pcbStoreEID);

SCODE STDMETHODCALLTYPE MyAllocateBuffer( ULONG cbSize,	LPVOID FAR * lppBuffer);

SCODE STDMETHODCALLTYPE MyAllocateMore( ULONG cbSize, LPVOID lpObject, LPVOID FAR * lppBuffer);

ULONG STDAPICALLTYPE MyFreeBuffer(LPVOID lpBuffer);

HRESULT AllocSPropValue(ULONG cValues, LPSPropValue lpPropArraySrc, LPSPropValue *lppPropArrayDst);



void LogEntry(LPSTR lpszStr);



void LogReturn(LPSTR szFun, HRESULT hRes);
HRESULT AllocSPropTagArray(LPSPropTagArray src, LPSPropTagArray * dst);
STDMETHODIMP GetPropExtraSize( ULONG ulPropTag, union _PV Value, ULONG & cbSize, LPVOID * ppVoid);
void FixUpFlatPropPointers (LPH_FlatSPropValue pNode, LPBYTE pByte);
STDMETHODIMP FlattenProp( LPSPropValue pProp, LPH_FlatSPropValue * ppNode );
HRESULT DumpSRowSet(LPSRowSet lpRowSet);